import Vue from 'vue'
import Router from 'vue-router'
import Home from "@/views/home/Home"
import Recommend from "@/views/recommend/Recommend"
import Search from "@/views/search/Search"
import Chat from "@/views/chat/Chat"
import Mine from "@/views/mine/Mine"
import Details from "@/views/details/Details"
import Login from "@/views/login"


Vue.use(Router)

export default new Router({
  routes: [
     {
       path:"/",
       redirect:"/home/hot"
     },
     {
       path:"/home",
       name:"home",
       redirect:"/home/hot",
       component:Home,
       children:[
          {
            path:"hot",
            component:()=>import ("@/views/home/pages/hot")
          },
          {
            path:"cloth",
            component:()=>import ("@/views/home/pages/cloth")
          },
          {
            path:"proudects",
            component:()=>import ("@/views/home/pages/proudects")
          },
          {
            path:"babys",
            component:()=>import ("@/views/home/pages/babys")
          }
       ]
     },
     {
      path:"/recommend",
      name:"Recommend",
      component:Recommend
    },
    {
      path:"/search",
      name:"Search",
      component:Search
    },
    {
      path:"/chat",
      name:"Chat",
      component:Chat
    },
    {
      path:"/mine",
      name:"Mine",
      component:Mine,
      beforeEnter:(to,from,next)=>{ //路由守卫
          let tel=localStorage.getItem("tel");
          if(tel){
            next()
          }else{
            next("/login")
          }
      }
    },
    {
      path:"/details",
      name:"Details",
      component:Details
    },
    {
      path:"/login",
      name:"Login",
      component:Login
    }
  ]
})
